import Mock from 'mockjs'
const adminMenus = [
    {
        path: '/home',
        name: 'home',
        label: '首页',
        icon: 's-home',
        url: 'home',
    },
    {
        path: '/mall',
        name: 'mall',
        label: '商品管理',
        icon: 's-home',
        url: 'mall',
    },
    {
        path: '/user',
        name: 'user',
        label: '用户管理',
        icon: 'user',
        url: 'user',
    },
    {
        label: '其他',
        icon: 'location',
        children: [
            {
                path: '/other/page1',
                name: 'page1',
                label: '页面1',
                icon: 'setting',
                url: 'other/page1',
            },
            {
                path: '/other/page2',
                name: 'page2',
                label: '页面2',
                icon: 'setting',
                url: 'other/page2',
            }
        ]
    },
];

const userMenus = [
    {
        path: '/home',
        name: 'home',
        label: '首页',
        icon: 's-home',
        url: 'home'
    },
    {
        path: '/mall',
        name: 'mall',
        label: '商品管理',
        icon: 's-home',
        url: 'mall'
    }
]
export default {
    getMenu: config => {
        const { username, password } = JSON.parse(config.body);
        // 先判断用户是否存在
        // 判断账号和密码是否对应
        if (username === 'admin' && password === 'admin') {
            return {
                code: 200,
                data: {
                    menu: adminMenus,
                    token: Mock.Random.guid(),
                    message: '获取成功'
                }
            }
        } else if (username === 'user' && password === 'user') {
            return {
                code: 200,
                data: {
                    menu: userMenus,
                    token: Mock.Random.guid(),
                    message: '获取成功'
                }
            }
        } else {
            return {
                code: 401,
                data: {
                    message: '密码错误'
                }
            }
        }
    }
}